package com.tudouji.project.weigh.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tudouji.framework.aspectj.lang.annotation.Log;
import com.tudouji.framework.aspectj.lang.enums.BusinessType;
import com.tudouji.project.weigh.domain.WeightData;
import com.tudouji.project.weigh.service.IWeightDataService;
import com.tudouji.framework.web.controller.BaseController;
import com.tudouji.framework.web.domain.AjaxResult;
import com.tudouji.common.utils.poi.ExcelUtil;
import com.tudouji.framework.web.page.TableDataInfo;

/**
 * 过磅记录接口Controller
 * 
 * @author tudouji
 * @date 2023-03-22
 */
@RestController
@RequestMapping("/weigh/data")
public class WeightDataController extends BaseController
{
    @Autowired
    private IWeightDataService weightDataService;

    /**
     * 查询过磅记录接口列表
     */
    @PreAuthorize("@ss.hasPermi('weigh:data:list')")
    @GetMapping("/list")
    public TableDataInfo list(WeightData weightData)
    {
        startPage();
        List<WeightData> list = weightDataService.selectWeightDataList(weightData);
        return getDataTable(list);
    }

    /**
     * 导出过磅记录接口列表
     */
    @PreAuthorize("@ss.hasPermi('weigh:data:export')")
    @Log(title = "过磅记录接口", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(WeightData weightData)
    {
        List<WeightData> list = weightDataService.selectWeightDataList(weightData);
        ExcelUtil<WeightData> util = new ExcelUtil<WeightData>(WeightData.class);
        return util.exportExcel(list, "data");
    }

    /**
     * 获取过磅记录接口详细信息
     */
    @PreAuthorize("@ss.hasPermi('weigh:data:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(weightDataService.selectWeightDataById(id));
    }

    /**
     * 新增过磅记录接口
     */
    @PreAuthorize("@ss.hasPermi('weigh:data:add')")
    @Log(title = "过磅记录接口", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WeightData weightData)
    {
        return toAjax(weightDataService.insertWeightData(weightData));
    }

    /**
     * 修改过磅记录接口
     */
    @PreAuthorize("@ss.hasPermi('weigh:data:edit')")
    @Log(title = "过磅记录接口", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WeightData weightData)
    {
        return toAjax(weightDataService.updateWeightData(weightData));
    }

    /**
     * 删除过磅记录接口
     */
    @PreAuthorize("@ss.hasPermi('weigh:data:remove')")
    @Log(title = "过磅记录接口", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(weightDataService.deleteWeightDataByIds(ids));
    }
}
